#include <stdafx.h>
#include <wwdef.h>
#include "io.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



rdbunit::rdbunit(void)
{

}

rdbunit::~rdbunit(void)
{

}

void rdbunit::init(void)
{
    u32 getword = 0;
    l3str getstr = _T("0.0.0.0");
    bl ret1 = bfalse, ret2 = bfalse;
    ret1 = l3Getu32FromRegistry(HKEY_LOCAL_MACHINE, _T("SoftWare\\l3Platform\\Wisewires"), _T("wwuport"), getword );
    ret2 = l3GetStrFromRegistry(HKEY_LOCAL_MACHINE, _T("SoftWare\\l3Platform\\Wisewires"), _T("wwuip"), getstr);

    minet.setaddr((u16)getword, (xch*)getstr);
    TRACE("[WISE UPDATE CHK]getconinfo ret:%d/%d / port:%d / ip:%s", ret1, ret2, getword, (xch*)getstr);

    xch tmp[SERVICE_NAMELEN];
    GetModuleFileName(NULL, tmp, SERVICE_NAMELEN);

    xsz len = l3xstrlen(tmp);
    xsz i = 0;
    for(i = len - 1; i >= 0; --i) 
    {
        if(tmp[i] == _T('\\')) 
            break;
    }
    l3xstrcpy(mmodulepath, tmp);
    mmodulepath[i] = xnull;
}

void rdbunit::getfileinfo(void)
{
    long                hFile = 0L;
    struct _finddata_t    c_file;
    CString                SearchPath = "";
    CString                valid_filenames[100];    // assumes max 100 DLL's!!!!!!
    CString                command_line;

    l3filever fver;
    l3hlist flist;
    l3xdata fname;

    command_line = GetCommandLine();            // so we know ehere to look for DLL's
    command_line = command_line.Left(command_line.Find("wisechk"));    // lose exe name
    command_line = command_line.Right(command_line.GetLength() - 1);            // lose leading "

    SearchPath = command_line + "*.dll";
    hFile = _findfirst(SearchPath, &c_file);
    if (hFile != -1L)
    {
        do
        {
            fname = c_file.name;
            flist.set(fname);
        } while (_findnext(hFile, &c_file) == 0);
        _findclose(hFile);
    }

    SearchPath = command_line + "*.exe";
    hFile = _findfirst(SearchPath, &c_file);
    if (hFile != -1L)
    {
        do
        {
            fname = c_file.name;
            flist.set(fname);
        } while (_findnext(hFile, &c_file) == 0);
        _findclose(hFile);
    }

    flist.first();
    mlfset.createset(flist.count(), 5);

    for (u32 i = 0; i < mlfset.mnr; i++)
    {
        fver.mname = (sch*)(*flist.get());
        fver.getver();

        mlfset.mrcd[i][0] = (sch*)fver.mname;
        mlfset.mrcd[i][1] = fver.mmajor;
        mlfset.mrcd[i][2] = fver.mminor;
        mlfset.mrcd[i][3] = fver.mbdate;
        mlfset.mrcd[i][4] = fver.mbnum;
        TRACE("[%s] %d/%d/%d/%d\n", (sch*)fver.mname, fver.mmajor, fver.mminor, fver.mbdate, fver.mbnum);
        flist.clear();
    }

    return;
}